package com.xinzhi.dao;

import com.xinzhi.entity.Goods;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;


public class GoodsDao {
    /**
     * 商品连接类
     */
    public ArrayList<Goods> getAllusr(String type) {
        Connection conn = null;
        PreparedStatement stat = null;
        ResultSet rs = null;
        ArrayList<Goods> goods = new ArrayList<>();
        try {
            conn = BaseDao.getConn();
            String sql = "select * from goods where type = ? ";
            stat = conn.prepareStatement(sql);
            stat.setString(1,type);
            rs = stat.executeQuery();
            while (rs.next()){
                Goods g = new Goods();
                g.setName(rs.getNString("name"));
                g.setPrice(rs.getInt("price"));
                g.setType(rs.getString("type"));
                goods.add(g);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            BaseDao.closeAll(rs,stat,conn);
        }
        return goods;
    }

}
